<template>
  <page-main>
    <template #right>
      <!-- <el-button type="primary" icon="plus" @click="handleOperate(refAddEdit,{},'add')">新增</el-button> -->
      <!-- <el-button type="danger" icon="delete" @click="handleDelete(tableData.checkedIds)">批量删除</el-button> -->
      <el-button type="default" icon="download" @click="handleExport('活动签到','/admin/checkins/export', {})">导出</el-button>
    </template>
    <search-form ref="refSearchForm" @confirm="handleSearch" />
    <el-table
          v-loading="tableData.loading"
          ref="refTable"
          :data="tableData.list"
          stripe
          border
          style="width: 100%"
          row-key="id"
          :header-cell-style="tableData.headerCellStyle"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
          @selection-change="selectCheckbox"
          >
          <!-- <el-table-column label="ID" prop="id" width="80"/> -->
          <el-table-column label="用户Id" prop="userId"/>
          <el-table-column label="金额" prop="amount"/>
          <el-table-column label="状态" prop="status">
            <template #default="scope">
              {{proxy.$util.selectName(scope.row.status, optionData.withdrawalStatus)}}
            </template>
          </el-table-column>
          <el-table-column label="审核人ID" prop="approverUserId"/>
          <el-table-column label="创建时间" prop="createTime"/>
          <el-table-column label="操作" fixed="right" width="280" align="center">
            <template #default="scope">
              <el-button
                size="small"
                type="primary"
                text
                @click="handleAudit(scope.row, 'approve')"
              >同意</el-button>
              <el-button
                size="small"
                type="danger"
                text
                @click="handleAudit(scope.row, 'reject')"
              >拒绝</el-button>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          :current-page="pageData.current"
          :page-size="pageData.size"
          :page-sizes="pageData.pageSizes"
          :total="pageData.total"
          background
          style="padding: 30px 0; text-align: center;"
          layout="total, sizes, prev, pager, next, jumper"
          @current-change="getList"
          @size-change="sizeChange"
        />
        <add-edit ref="refAddEdit" name="品牌" @confirm="getList(dlgAddEdit.type == 'add'? 1 : pageData.current)"></add-edit> 
        <show-detail ref="refShowDetail" />
  </page-main>
</template>

<script setup lang="ts">
import { ElMessage, ElMessageBox } from 'element-plus'
// import {onMounted, ref, reactive, provide,defineAsyncComponent, getCurrentInstance, ComponentInternalInstance} from 'vue';
let obj = {
  pageApi: '/admin/withdrawal/page',
  deleteApi: '/admin/withdrawal',
  primaryKey: 'checkinId',
  searchFixed:{},
}
import { useList } from '/@/assets/compositionFn/list';
let { dlgAddEdit, tableData, pageData, optionDataStore, getList, handleSearch, sizeChange, selectCheckbox, setDefaultCheckbox, handleOperate, handleDelete, handleDeleteMultiple, handleExport } = useList(obj);
const SearchForm = defineAsyncComponent(() => import('./components/SearchForm.vue'));
const AddEdit = defineAsyncComponent(() => import('./components/AddEdit.vue'));
const ShowDetail = defineAsyncComponent(() => import('./components/ShowDetail.vue'));
const {proxy} :any = getCurrentInstance() as ComponentInternalInstance;
const refSearchForm = ref();
const refTable = ref();
const refAddEdit = ref();
const refShowDetail = ref();
const optionData:any = reactive({});

provide('optionData', optionData);
const getInitData = async ()=>{
  optionData.withdrawalStatus = await optionDataStore.getDictList('withdrawal_status');
};
const handleAudit = (row, type) => {
  let tips = type == 'reject' ? '拒绝' : '同意';
  ElMessageBox.confirm(
    '确定要'+tips+'该提现?',
    '提示',
  ).then(() => {
      proxy.$request('post', '/admin/withdrawal/'+type+'/' + row.id, {}, (data,msg) => {
        ElMessage({type: 'success', message: '提交成功'});
        getList();
      })
    })
    .catch(() => {
      
    })
}
onMounted(async () => {
  await getInitData();
  getList()
})
</script>

<style>

</style>